package com.usts.edu.web.controller.base;

import java.lang.reflect.ParameterizedType;

/**
 * Created by lenovo on 2019/5/9.
 */
public abstract class BaseController<T> {

    public static String MANAGE_PAGE;  //管理页面
    public static String INFO_PAGE;  //列表页面
    public static String EDIT_PAGE;  //编辑页面

    //定义常量
    public static final String MANAGE = "manage";  //管理
    public static final String INFO = "info";  //列表
    public static final String EDIT = "edit";  //编辑

    public BaseController() {

        //1.获取泛型的真实类型
        ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
        System.out.println(type);

        Class<?> modelClass = (Class<?>) type.getActualTypeArguments()[0];

        //2.获取模块名
        String moduleName = modelClass.getSimpleName().toLowerCase();

        //3.给静态页面赋值
        MANAGE_PAGE = moduleName + "/" + MANAGE;
        INFO_PAGE = moduleName + "/" + INFO;
        EDIT_PAGE = moduleName + "/" + EDIT;

    }
}
